import 'dart:collection';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:opene/app_utils.dart';
import 'package:opene/home/homedialogscreen.dart';
import 'package:opene/home/search/search.dart';
import 'package:opene/ui/ankerlabel/AnkerLabelscreen.dart';
import 'package:opene/ui/ankermatch/ankermatchscreen.dart';
import 'package:opene/ui/b2blabel/b2blabelscreen.dart';
import 'package:opene/ui/b2bpick/b2bpickscreen.dart';
import 'package:opene/ui/b2btrailer/b2btrailerscreen.dart';
import 'package:opene/ui/b2coblpn/b2coblpnscreen.dart';
import 'package:opene/ui/b2cpick/b2cpickscreen.dart';
import 'package:opene/ui/b2ctrailer/b2ctrailerscreen.dart';
import 'package:opene/ui/checkin/checkin.dart';
import 'package:opene/ui/cms/checkin/cmscheckinscreen.dart';
import 'package:opene/ui/cms/oblpn/cmsoblpnscreen.dart';
import 'package:opene/ui/cms/putatay/cmsputatayscreen.dart';
import 'package:opene/ui/cms/tally/cmstallyscreen.dart';
import 'package:opene/ui/fbamatch/fbamatchscreen.dart';
import 'package:opene/ui/fbapick/fbapickscreen.dart';
import 'package:opene/ui/fbatransfer/fbatransferscreen.dart';
import 'package:opene/ui/inventorytransfer/lpnmapping/lpnmappingscreen.dart';
import 'package:opene/ui/inventorytransfer/putaway/inventoryputawayscreen.dart';
import 'package:opene/ui/lpnphoto/lpnphotoscreen.dart';
import 'package:opene/ui/manage/adjust/adjustscreen.dart';
import 'package:opene/ui/manage/devicebind/devicebindscreen.dart';
import 'package:opene/ui/manage/merge/mergescreen.dart';
import 'package:opene/ui/putaway/putawayscreen.dart';
import 'package:opene/ui/returns/finalprocess/finalprocessscreen.dart';
import 'package:opene/ui/returns/newpreprocess/newpreprocessscreen.dart';
import 'package:opene/ui/returns/newputaway/returnsnewputatayscreen.dart';
import 'package:opene/ui/returns/oldputatay/returnsoldputatayscreen.dart';
import 'package:opene/ui/returns/trailer/returnstrailerscreen.dart';
import 'package:opene/ui/urgent/urgentinscreen.dart';
import 'package:opene/ui/urgent/urgentoutscreen.dart';
import 'package:opene/ui/urgent/urgentputawayscreen.dart';
import 'package:opene/ui/vas/putaway/vasputatayscreen.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../app_constant.dart';
import '../app_theme.dart';
import '../net/network_manager.dart';
import '../net/response/base_response.dart';
import '../ui/tally/tallyscreen.dart';
import 'authorize_bean.dart';

class HomeScreen extends StatefulWidget {
  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateMixin {
  final controller = ScrollController();

  Map<String, String> authorizeMap = new HashMap();

  @override
  void initState() {
    super.initState();
    fetchData();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(left: 15, top: 15, right: 15, bottom: 0),
      color: MyAppTheme.background,
      child: SingleChildScrollView(
        controller: controller, // 设置控制器
        child: Column(
          // This next line does the trick.
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            SizedBox(
              height: 40, // 高度
              width: double.infinity,
              child: ElevatedButton(
                child: Text(
                  "Search",
                  style: TextStyle(
                    color: MyAppTheme.darkText,
                  ),
                ),
                style: ButtonStyle(
                  textStyle: MaterialStateProperty.all(
                    Theme.of(context).textTheme.subtitle1,
                  ),
                  alignment: Alignment.centerLeft,
                  elevation: MaterialStateProperty.all(0),
                  backgroundColor: MaterialStateProperty.all<Color>(Colors.white),
                  shape: MaterialStateProperty.all<RoundedRectangleBorder>(
                    RoundedRectangleBorder(
                      side: BorderSide(width: 1, color: MyAppTheme.nearlyBlue),
                      borderRadius: const BorderRadius.all(Radius.circular(20.0)),
                    ),
                  ),
                ),
                onPressed: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(builder: (context) => Search()),
                  );
                },
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 10),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_checkin'] != null) || (authorizeMap['pda_tally'] != null) || (authorizeMap['pda_damage'] != null) || (authorizeMap['pda_lpn_photo'] != null) || (authorizeMap['pda_putaway'] != null)) ? true : false,
              child: Text("INBOUND", style: MyAppTheme.body1),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_checkin'] != null) || (authorizeMap['pda_tally'] != null) || (authorizeMap['pda_damage'] != null) || (authorizeMap['pda_lpn_photo'] != null) || (authorizeMap['pda_putaway'] != null)) ? true : false,
              child: Container(
                margin: const EdgeInsets.only(left: 0, top: 5, right: 0, bottom: 10),
                child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(8.0)),
                  child: Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 10),
                    child: Row(
                      children: <Widget>[
                        Visibility(
                          // visible: authorizeMap['pda_checkin'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => Checkin()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_checkin.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Checkin",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_tally'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => TallyScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_tally.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Tally",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_damage'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Image.asset(
                                  'assets/images/home/ic_home_damage.png',
                                  width: 30,
                                  height: 30,
                                ),
                                Text(
                                  "Damage",
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: MyAppTheme.caption,
                                ),
                              ],
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_lpn_photo'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => LpnPhotoScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_lpn_photo.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "LPN Photo",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_putaway'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => PutawayScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_putaway.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Putaway",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_pickUp'] != null) || (authorizeMap['pda_lable'] != null) || (authorizeMap['pda_trailer#'] != null) || (authorizeMap['pda_outBoundLPN'] != null)) ? true : false,
              child: Text("OUTBOUND(B2C)", style: MyAppTheme.body1),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_pickUp'] != null) || (authorizeMap['pda_lable'] != null) || (authorizeMap['pda_trailer#'] != null) || (authorizeMap['pda_outBoundLPN'] != null)) ? true : false,
              child: Container(
                margin: const EdgeInsets.only(left: 0, top: 5, right: 0, bottom: 10),
                child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(8.0)),
                  child: Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 10),
                    child: Row(
                      children: <Widget>[
                        Visibility(
                          // visible: authorizeMap['pda_pickUp'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => B2CPickScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_pick.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "PickUp",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_lable'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {},
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_label.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Label",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_outBoundLPN'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => B2COBLPNScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_oblpn.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "OBLPN",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_trailer#'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => B2CTrailerScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_trailer.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Trailer#",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_b2bPick'] != null) || (authorizeMap['pda_b2bLabel'] != null) || (authorizeMap['pda_b2bPalletTag'] != null) || (authorizeMap['pda_b2bTrailer#'] != null)) ? true : false,
              child: Text("OUTBOUND(B2B)", style: MyAppTheme.body1),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_b2bPick'] != null) || (authorizeMap['pda_b2bLabel'] != null) || (authorizeMap['pda_b2bPalletTag'] != null) || (authorizeMap['pda_b2bTrailer#'] != null)) ? true : false,
              child: Container(
                margin: const EdgeInsets.only(left: 0, top: 5, right: 0, bottom: 10),
                child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(8.0)),
                  child: Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 10),
                    child: Row(
                      children: <Widget>[
                        Visibility(
                          // visible: authorizeMap['pda_b2bPick'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => B2BPickScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_b2b_pick.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Pick",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_b2bLabel'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => B2BLabelScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_b2b_label.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Lable",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_b2bPalletTag'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_b2b_pallet.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "PalletTag",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_b2bTrailer#'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => B2BTrailerScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_b2b_trailer.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Trailer#",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_fba_pick'] != null) || (authorizeMap['pda_fba_match'] != null)) ? true : false,
              child: Text("FBA Transload", style: MyAppTheme.body1),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_fba_pick'] != null) || (authorizeMap['pda_fba_match'] != null)) ? true : false,
              child: Container(
                margin: const EdgeInsets.only(left: 0, top: 5, right: 0, bottom: 10),
                child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(8.0)),
                  child: Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 10),
                    child: Row(
                      children: <Widget>[
                        Visibility(
                          // visible: authorizeMap['pda_fba_match'] == null ? false : true,
                          child: Expanded(
                              flex: 1, //设置权重
                              child: GestureDetector(
                                onTap: () {
                                  Navigator.push(
                                    context,
                                    MaterialPageRoute(builder: (context) => FBAMatchScreen()),
                                  );
                                },
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Image.asset(
                                      'assets/images/home/ic_home_fba_match.png',
                                      width: 30,
                                      height: 30,
                                    ),
                                    Text(
                                      "Match",
                                      maxLines: 1,
                                      overflow: TextOverflow.ellipsis,
                                      style: MyAppTheme.caption,
                                    ),
                                  ],
                                ),
                              )),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_fba_pick'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => FBAPickScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_fba_pick.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "FbaPick",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_preProcess'] != null) ||
              //         (authorizeMap['pda_finalProcess'] != null) ||
              //         (authorizeMap['pda_returnPutaway'] != null) ||
              //         (authorizeMap['pda_returnTrailer#'] != null) ||
              //         (authorizeMap['pda_newPreProcess'] != null) ||
              //         (authorizeMap['pda_newReturnPutaway'] != null))
              //     ? true
              //     : false,
              child: Text("Returns", style: MyAppTheme.body1),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_preProcess'] != null) ||
              //         (authorizeMap['pda_finalProcess'] != null) ||
              //         (authorizeMap['pda_returnPutaway'] != null) ||
              //         (authorizeMap['pda_returnTrailer#'] != null) ||
              //         (authorizeMap['pda_newPreProcess'] != null) ||
              //         (authorizeMap['pda_newReturnPutaway'] != null))
              //     ? true
              //     : false,
              child: Container(
                margin: const EdgeInsets.only(left: 0, top: 5, right: 0, bottom: 10),
                child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(8.0)),
                  child: Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 10),
                    child: Row(
                      children: <Widget>[
                        Visibility(
                          // visible: authorizeMap['pda_preProcess'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => NewPreprocessScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_returns.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "PreProcess",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_finalProcess'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => FinalProcessScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_finalprocess.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "FinalProcess",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_returnPutaway'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => ReturnsOldPutatayScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_returns_putaway.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Old Putaway",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_returnTrailer#'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => ReturnsTrailerScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_returns_trailer.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Trailer#",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_newPreProcess'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => ReturnsNewPutatayScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_returns.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Bounce",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_newReturnPutaway'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => ReturnsNewPutatayScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_returns_new_putaway.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Putaway",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
            Visibility(
              // visible: authorizeMap['pda_vasPutaway'] == null ? false : true,
              child: Text("Value-Add", style: MyAppTheme.body1),
            ),
            Visibility(
              // visible: authorizeMap['pda_vasPutaway'] == null ? false : true,
              child: Container(
                margin: const EdgeInsets.only(left: 0, top: 5, right: 0, bottom: 10),
                child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(8.0)),
                  child: Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 10),
                    child: Row(
                      children: <Widget>[
                        Visibility(
                          // visible: authorizeMap['pda_vasPutaway'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => VASPutatayScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_add_putaway.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Putaway",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_cycleCount'] != null) || (authorizeMap['pda_transfer'] != null) || (authorizeMap['pda_adjustment'] != null) || (authorizeMap['pda_merge'] != null) || (authorizeMap['pda_print'] != null) || (authorizeMap['pda_DeviceBind'] != null) || (authorizeMap['pda_Patrol'] != null)) ? true : false,
              child: Text("MANAGE", style: MyAppTheme.body1),
            ),
            Visibility(
              // visible:((authorizeMap['pda_cycleCount'] != null) || (authorizeMap['pda_transfer'] != null) || (authorizeMap['pda_adjustment'] != null) || (authorizeMap['pda_merge'] != null) || (authorizeMap['pda_print'] != null) || (authorizeMap['pda_DeviceBind'] != null) || (authorizeMap['pda_Patrol'] != null)) ? true : false,
              child: Container(
                margin: const EdgeInsets.only(left: 0, top: 5, right: 0, bottom: 10),
                child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(8.0)),
                  child: Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 10),
                    child: Row(
                      children: <Widget>[
                        Visibility(
                          // visible: authorizeMap['pda_cycleCount'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Image.asset(
                                  'assets/images/home/ic_home_cyclecount.png',
                                  width: 30,
                                  height: 30,
                                ),
                                Text(
                                  "Cyclecount",
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: MyAppTheme.caption,
                                ),
                              ],
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_transfer'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Image.asset(
                                  'assets/images/home/ic_home_transfer.png',
                                  width: 30,
                                  height: 30,
                                ),
                                Text(
                                  "Transfer",
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: MyAppTheme.caption,
                                ),
                              ],
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_adjustment'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => AdjustScreen()),
                                );
                              },
                              child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Image.asset(
                                  'assets/images/home/ic_home_adjust.png',
                                  width: 30,
                                  height: 30,
                                ),
                                Text(
                                  "Adjustment",
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: MyAppTheme.caption,
                                ),
                              ],
                            ),),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_merge'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => MergeScreen()),
                                );
                              },
                              child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Image.asset(
                                  'assets/images/home/ic_home_merge.png',
                                  width: 30,
                                  height: 30,
                                ),
                                Text(
                                  "Merge",
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: MyAppTheme.caption,
                                ),
                              ],
                            ),),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_print'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Image.asset(
                                  'assets/images/home/ic_home_print.png',
                                  width: 30,
                                  height: 30,
                                ),
                                Text(
                                  "Print",
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: MyAppTheme.caption,
                                ),
                              ],
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_DeviceBind'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => DeviceBindScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_devicebind.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "DeviceBind",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_Patrol'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Image.asset(
                                  'assets/images/home/ic_home_patrol.png',
                                  width: 30,
                                  height: 30,
                                ),
                                Text(
                                  "Patrol",
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: MyAppTheme.caption,
                                ),
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_cms_unload'] != null) || (authorizeMap['pda_cms_tally'] != null) || (authorizeMap['pda_cms_putaway'] != null) || (authorizeMap['pda_cms_outbound'] != null)) ? true : false,
              child: Text("Container Crossing Dock", style: MyAppTheme.body1),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_cms_unload'] != null) || (authorizeMap['pda_cms_tally'] != null) || (authorizeMap['pda_cms_putaway'] != null) || (authorizeMap['pda_cms_outbound'] != null)) ? true : false,
              child: Container(
                margin: const EdgeInsets.only(left: 0, top: 5, right: 0, bottom: 10),
                child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(8.0)),
                  child: Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 10),
                    child: Row(
                      children: <Widget>[
                        Visibility(
                          // visible: authorizeMap['pda_cms_unload'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => CMSCheckinScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_container_unload.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Checkin",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_cms_tally'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => CMSTallyScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_container_tally.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Tally",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_cms_putaway'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => CMSPutatayScreen()),
                                );
                              },
                              child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Image.asset(
                                  'assets/images/home/ic_home_container_putaway.png',
                                  width: 30,
                                  height: 30,
                                ),
                                Text(
                                  "Putaway",
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: MyAppTheme.caption,
                                ),
                              ],
                            ),),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_cms_outbound'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => CMSOBLPNScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_container_oblpn.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "OBLPN",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
            Visibility(
              // visible: authorizeMap['pda_FBATransfer'] == null ? false : true,
              child: Text("MANAGE(FBA)", style: MyAppTheme.body1),
            ),
            Visibility(
              // visible: authorizeMap['pda_FBATransfer'] == null ? false : true,
              child: Container(
                margin: const EdgeInsets.only(left: 0, top: 5, right: 0, bottom: 10),
                child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(8.0)),
                  child: Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 10),
                    child: Row(
                      children: <Widget>[
                        Visibility(
                          // visible: authorizeMap['pda_FBATransfer'] == null ? false : true,
                          child: Expanded(
                              flex: 1, //设置权重
                              child: GestureDetector(
                                onTap: () {
                                  Navigator.push(
                                    context,
                                    MaterialPageRoute(builder: (context) => FBATransferScreen()),
                                  );
                                },
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Image.asset(
                                      'assets/images/home/ic_home_fba_transfer.png',
                                      width: 30,
                                      height: 30,
                                    ),
                                    Text(
                                      "FBATransfer",
                                      maxLines: 1,
                                      overflow: TextOverflow.ellipsis,
                                      style: MyAppTheme.caption,
                                    ),
                                  ],
                                ),
                              )),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_urgent'] != null) || (authorizeMap['pda_inventoryTransfer'] != null) || (authorizeMap['pda_ankerLabel'] != null) || (authorizeMap['pda_ankerMatch'] != null)) ? true : false,
              child: Text("Relocate", style: MyAppTheme.body1),
            ),
            Visibility(
              // visible: ((authorizeMap['pda_urgent'] != null) || (authorizeMap['pda_inventoryTransfer'] != null) || (authorizeMap['pda_ankerLabel'] != null) || (authorizeMap['pda_ankerMatch'] != null)) ? true : false,
              child: Container(
                margin: const EdgeInsets.only(left: 0, top: 5, right: 0, bottom: 10),
                child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(8.0)),
                  child: Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 10),
                    child: Row(
                      children: <Widget>[
                        Visibility(
                          // visible: authorizeMap['pda_urgent'] == null ? false : true,
                          child: Expanded(
                              flex: 1, //设置权重
                              child: GestureDetector(
                                onTap: () {
                                  showDialog(
                                    context: context,
                                    builder: (context) => UrgentDialog(),
                                  ).then((value) => {
                                        if ((value != null) && (value == 1))
                                          {
                                            Navigator.push(
                                              context,
                                              MaterialPageRoute(builder: (context) => UrgentOutScreen()),
                                            )
                                          }
                                        else if ((value != null) && (value == 2))
                                          {
                                            Navigator.push(
                                              context,
                                              MaterialPageRoute(builder: (context) => UrgentInScreen()),
                                            )
                                          }
                                        else if ((value != null) && (value == 3))
                                          {
                                            Navigator.push(
                                              context,
                                              MaterialPageRoute(builder: (context) => UrgentPutawayScreen()),
                                            )
                                          }
                                      });
                                },
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Image.asset(
                                      'assets/images/home/ic_home_urgent.png',
                                      width: 30,
                                      height: 30,
                                    ),
                                    Text(
                                      "Urgent",
                                      maxLines: 1,
                                      overflow: TextOverflow.ellipsis,
                                      style: MyAppTheme.caption,
                                    ),
                                  ],
                                ),
                              )),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_inventoryTransfer'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                showDialog(
                                  context: context,
                                  builder: (context) => InventoryTransferDialog(),
                                ).then((value) => {
                                      if ((value != null) && (value == 1))
                                        {
                                          Navigator.push(
                                            context,
                                            MaterialPageRoute(builder: (context) => LpnMappingScreen()),
                                          )
                                        }
                                      else if ((value != null) && (value == 2))
                                        {
                                          Navigator.push(
                                            context,
                                            MaterialPageRoute(builder: (context) => InventoryPutawayScreen()),
                                          )
                                        }
                                    });
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_stock_transfer.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "Inventory Transfer",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_ankerLabel'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => AnkerLabelScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_ankerlabel.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "AnkerLabel",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          // visible: authorizeMap['pda_ankerMatch'] == null ? false : true,
                          child: Expanded(
                            flex: 1, //设置权重
                            child: GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => AnkerMatchScreen()),
                                );
                              },
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image.asset(
                                    'assets/images/home/ic_home_arkermatch.png',
                                    width: 30,
                                    height: 30,
                                  ),
                                  Text(
                                    "AnkerMatch",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: MyAppTheme.caption,
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Future<void> setAuthorizes() async {
      var sp = await SharedPreferences.getInstance();
      var string = sp.getString(Constants.authorize);
      if(Utils.isEmpty(string)){
        return;
      }
      List<Authorize> authorizes = new List<dynamic>.from(json.decode(string)).map((userJson) => Authorize.fromJson(userJson)).toList();
      if(authorizes==null){
        return;
      }

      authorizes.forEach((element) {
        authorizeMap[element.code] = element.name;
      });
      setState(() {});
  }
  Future<void> fetchData() async {
    Map<String, dynamic> map = new HashMap();
    map['app'] = "jms";

    BaseResponse baseResponse = await NetworkManager().request(context, Constants.authorize, params: map);
    print(baseResponse.code);
    if (baseResponse.code == 200) {
      List<Authorize> authorizes = new List<dynamic>.from(baseResponse.data).map((userJson) => Authorize.fromJson(userJson)).toList();
      print(authorizes.length);

      String jsonStr = jsonEncode(authorizes);
      var sp = await SharedPreferences.getInstance();
      sp.setString(Constants.authorize, jsonStr);

      setAuthorizes();
    }
  }
}
